home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol06 / 02 / lanman2 / pbxsrv.h < prev    next >
C/C++ Source or Header  |  1991-02-28  |  11KB  |  226 lines

  1. /*-------------------------------------------------------------------
  2.   PBXSRV.H -- Global data, structures, and prototypes used by PBX
  3.               Note, this file assumes LAN.H has been included.
  4.  
  5.   Author:  Brendan Dixon
  6.            Microsoft, inc.
  7.            LAN Manager Developer Support
  8.  
  9.   This code example is provided for demonstration purposes only.
  10.   Microsoft makes no warranty, either express or implied,
  11.   as to its usability in any given situation.
  12. -------------------------------------------------------------------*/
  13.  
  14. #ifndef _PBXSRVH
  15. #define _PBXSRVH
  16.  
  17. #ifdef INCL_GLOBAL
  18. #define GLOBAL
  19. #else
  20. #define GLOBAL  extern
  21. #endif
  22.  
  23. #include  "pbxpkt.h"
  24.  
  25. // Defines ----------------------------------------------------------
  26. // LANMAN.INI section/keyword names
  27. #define PBXCOMPONENT      "PBX"           // Section name
  28. #define LINES             "LINES"         // Lines number
  29. #define LINEBUFSIZE       "LINEBUFSIZE"   // Line buffer size
  30. #define OPENLINES         "OPENLINES"     // Number of open lines
  31. #define CONNSPERTHREAD    "CONNSPERTHREAD"// Connections/Thread ratio
  32. #define AUDITING          "AUDITING"      // Audit enable/disable
  33.  
  34. #define MINLINES          2               // Min number of pipe lines
  35. #define MAXLINES          1000            // Max number of pipe lines
  36. #define DEFLINES          20              // Def number of pipe lines
  37.  
  38. #define MINLINEBUFSIZE    512             // Min line buffer size
  39. #define MAXLINEBUFSIZE    65535           // Max line buffer size
  40. #define DEFLINEBUFSIZE    4096            // Def line buffer size
  41.  
  42. #define MINOPENLINES      10              // Min open lines value
  43.  
  44. #define MINCONNSPERTHREAD 1               // Min connections/thread
  45.  
  46. #define MAXDOMAINS        5               // Max number of domains
  47. #define MINFHANDLES       50              // Min file handle guess
  48. #define MAXROUTERTHREADS  (MAXLINES/MINCONNSPERTHREAD)// Max Routers
  49. #define MPIPESTACKSIZE    4096            // MakePipe stack size
  50. #define PIPEMGRSTACKSIZE  4096            // PipeMgr  stack size
  51. #define ROUTERSTACKSIZE   4096            // Router   stack size
  52. #define LINEWAITTIMEOUT   5000L           // DosWaitNmPipe time out
  53. #define PBXINSTALLTIME    620L            // Est. PBX install time
  54. #define PBXUNINSTALLTIME  200L            // Est. PBX uninstall time
  55.  
  56. #define PBXSHUTDOWNMSG    "PBX on %s is stopping"   // Shutdown msg
  57.  
  58. #define PBXMEMNAME        "\\SHAREMEM\\MSJ\\PBXMEM" // Memory name
  59. #define PIPEMGRSEM        "\\SEM\\MSJ\\PBXPIPEMGR"  // PipeMgr sem
  60. #define ROUTERSEM         "\\SEM\\MSJ\\PBXROUTER%u" // Router  sem
  61.  
  62. #define PBXAUDITEVENT     (0x8000)        // PBX audit event type
  63.  
  64. // Basic macros
  65. #define ERRRPT(x,y,z)     { ErrorRpt(x, __FILE__, __LINE__, y, z); }
  66. #define MIN(x,y)          (x < y ? x : y)
  67.  
  68. // Types ------------------------------------------------------------
  69. // Error message severity
  70. typedef enum {
  71.   Error = 1,                              // Critical, PBX will stop
  72.   Warning,                                // Error, PBX will continue
  73.   Informational                           // No error
  74. } ERRSEV;
  75.  
  76. // Structures -------------------------------------------------------
  77. // Routing table entry
  78. typedef struct _ROUTEENT {
  79.   CHAR    pszName[NAMESIZE];              // Client name
  80.   USHORT  usClientType;                   // Client-type identifier
  81.                                           //   This value is client
  82.                                           //   dependent (however,
  83.                                           //   PBX reserves zero)
  84.   enum {                                  // Line state
  85.           Available = 1,                  //   Line is not created
  86.           Open,                           //   Line created
  87.           Owned,                          //   Owned by a client
  88.           Busy                            //   Line is connected
  89.   }       fState;
  90.   USHORT  usConnection;                   // Connection table index
  91.   USHORT  usWSpace;                       // Write space available
  92.   USHORT  usRData;                        // Amount of data to read
  93.   HPIPE   hLine;                          // Named-Pipe handle
  94. } ROUTEENT, _far *PROUTEENT;
  95.  
  96. // Router thread structure
  97. typedef struct _RTHREAD {
  98.   SHORT             sRouterID;            // Router thread ID
  99.   USHORT            cConnections;         // Number of connections
  100.   ULONG             semRAccess;           // Router access semaphore
  101.   HSEM              hsemRouter;           // Router semaphore
  102.   SEL               selLineBuf;           // Line buffer selector
  103.   CHAR         _far *pbLineBuf;           // Line buffer pointer
  104.   SEL               selRData;             // NPSS_RDATA selector
  105.   PROUTEENT    _far *aRData;              // NPSS_RDATA entry array
  106.   SEL               selClose;             // NPSS_CLOSE selector
  107.   PROUTEENT    _far *aClose;              // NPSS_CLOSE entry array
  108.   USHORT            usPSemStateSize;      // PIPESEMSTATE array size
  109.   SEL               selPSemState;         // PIPESEMSTATE selector
  110.   PIPESEMSTATE _far *aPSemState;          // PIPESEMSTATE array
  111. } RTHREAD;
  112.  
  113. // PBX shared memory structure
  114. typedef struct _PBXMEM {
  115.   ULONG             semPBXMem;            // Shared memory semaphore
  116.   ULONG             semPause;             // Pause service semaphore
  117.   ULONG             semExit;              // Exit  service semaphore
  118.   ULONG             semMakePipe;          // MakePipe semaphore
  119.   HSEM              hsemPipeMgr;          // PipeMgr  semaphore
  120.   USHORT            hMailslot;            // Mailslot handle
  121.   CHAR              pbMSlotBuf[255];      // Mailslot buffer
  122.   CHAR              pszPBXMsg[PBXMSGSIZE];// PBX message
  123.   USHORT            usPBXMsgSize;         // PBX message size
  124.   USHORT            usLines;              // Number of lines
  125.   USHORT            usLinesCreated;       // Number of created lines
  126.   USHORT            usLinesOwned;         // Number of owned lines
  127.   USHORT            usLineBufSize;        // Line buffer size
  128.   USHORT            usOpenLines;          // Open lines goal
  129.   USHORT            usConnsPerThread;     // Conns/Router ratio
  130.   BOOL              fAuditing;            // Audit or not flag
  131.   USHORT            usRThreadCnt;         // Number of Router threads
  132.   SEL               selBuf;               // PipeMgr buffer selector
  133.   CHAR         _far *pbBuf;               // PipeMgr work buffer
  134.   USHORT            usPSemStateSize;      // PIPESEMSTATE array size
  135.   SEL               selPSemState;         // PIPESEMSTATE selector
  136.   PIPESEMSTATE _far *aPSemState;          // PIPESEMSTATE array
  137.   SEL               selRTable;            // Routing table selector
  138.   ROUTEENT     _far *abRTable;            // Routing table array
  139.   SEL               selRouters;           // Router struct selector
  140.   RTHREAD      _far *abRouters;           // Router struct array
  141. } PBXMEM;
  142.  
  143. // PBX LAN Manager audit record structure
  144. // This structure maps the data portion of a PBX audit record
  145. // (the portion of the record not mapped by LAN Manager)
  146. typedef struct _PBXAUDIT {
  147.   enum {
  148.     Start = 1,                            // PBX starting event
  149.     RegUser,                              // User registered event
  150.     ConnectUsers,                         // Connection made event
  151.     DeregUser                             // User deregistered event
  152.   } fType;                                // Type of audit record
  153.  
  154.   // The following union contains the various structures used
  155.   // for the different events, only one structure at a time will
  156.   // be valid
  157.   union {
  158.     // Start event data
  159.     struct {
  160.       unsigned  usLines;                  // Number of lines
  161.       unsigned  usLineBufSize;            // Line buffer size
  162.       unsigned  usOpenLines;              // Open lines goal
  163.       unsigned  usConnsPerThread;         // Conns/Router thread
  164.     } pbStart;                            // Start data
  165.  
  166.     // Register event data
  167.     struct {
  168.       char  pszName[NAMESIZE];            // User name
  169.     } pbRegister;
  170.  
  171.     // Connect event data
  172.     struct {
  173.       char  pszSource[NAMESIZE];          // Source user name
  174.       char  pszTarget[NAMESIZE];          // Target user name
  175.     } pbConnect;
  176.  
  177.     // Deregister event data
  178.     struct {
  179.       char  pszName[NAMESIZE];            // User name
  180.     } pbDeregister;
  181.   };
  182. } PBXAUDIT;
  183.  
  184. // Globals ----------------------------------------------------------
  185. GLOBAL SEL          selPBXMem;            // Shared memory selector
  186. GLOBAL PBXMEM _far  *pbPBXMem;            // Shared memory pointer
  187. GLOBAL struct service_status ssStatus;    // LAN Man. Service struct
  188. GLOBAL ULONG        ulExitCode;             // LAN Man. Exit Code
  189. GLOBAL CHAR         pszExitText[STXTLEN+1]; // LAN Man. Exit Text
  190.  
  191. // Function Prototypes ----------------------------------------------
  192. // PBX threads
  193. void _cdecl main            (int argc, char *argv[]);// Main thread
  194. void _cdecl MakePipe        (void);               // MakePipe thread
  195. void _cdecl PipeMgr         (void);               // PipeMgr  thread
  196. void _cdecl Router          (USHORT usThreadNum); // Router   thread
  197.  
  198. // Initialization routines
  199. void  AllocatePipeMgrMem  (void);              // Get PipeMgr memory
  200. void  AllocateRouterMem   (void);              // Get Router memory
  201. void  AllocateRoutingTable(void);              // Get Routing table
  202. void  BuildPBXMsg         (void);              // Build PBX message
  203. void  CreateThreads       (void);              // Create children
  204.  
  205. // Internal work routines
  206. void  Deregister      (ROUTEENT _far *pbREnt); // Remove entry
  207. void  ErrorRpt        (PSZ    pszMsg,          // Error function
  208.                        PSZ    pszFile,
  209.                        USHORT usLine,
  210.                        USHORT usRC,
  211.                        ERRSEV esSev);
  212. void  ExitHandler     (void);                  // PBX Exit routine
  213. void  InstallSignals  (void);                  // Install signals
  214. BOOL  ReadPKT         (PCH    pbBuf,           // Read from a pipe
  215.                        USHORT usSize,
  216.                        ROUTEENT _far *pbREnt);
  217. BOOL  SendPKT         (PCH    pbBuf,           // Write to a pipe
  218.                        USHORT usSize,
  219.                        ROUTEENT _far *pbREnt);
  220.  
  221. // PBX signal handler
  222. void _far _pascal SignalHandler (USHORT usSigArg,
  223.                                  USHORT usSigNum);
  224.  
  225. #endif
  226.